package com.aaa.sbms.service;

import com.aaa.sbms.dao.TrainerDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @FileName:TraintServiceImpl
 * @Description:
 * @Author :99728
 * @Date: 2020/6/11 21:29
 * @Version:1.0.0
 */
@Service
public class TrainerServiceImpl implements TrainerService {

    @Autowired
    private TrainerDao trainerDao;

    /**
     * 培训师列表
     * @param map
     * @return
     */
    @Override
    public Map getlist(Map map) {
        List<Map> list = trainerDao.getlist(map);
        Map<Object, Object> resultMap = new HashMap<>();
        resultMap.put("list",list);
        return resultMap;
    }

    @Override
    public Map getPage(Map map) {
        //开始值： begin =(pageNo-1)*pageSize
        //结束值： end  =pageNo*pageSize+1
        //获取前面输入值，计算后放入参数中
        map.put("begin",(Integer.valueOf(map.get("pageNo")+"")-1)*Integer.valueOf(map.get("pageSize")+""));
        int pageSize = Integer.valueOf(map.get("pageSize").toString());
        map.put("pageSize",pageSize);
        //调用 dao获取数据
        List<Map> page = trainerDao.getPage(map);
        int total = trainerDao.getPageCount(map);
        //合并结果
        Map resultMap = new HashMap();
        resultMap.put("page",page);
        resultMap.put("total",total);
        return resultMap;
    }


    /**
     * 一条数据
     * @param trainerid
     * @return
     */
    @Override
    public Map onelist(int trainerid) {
        Map onelist = trainerDao.onelist(trainerid);
        HashMap<Object, Object> resultMap = new HashMap<>();
        String photopath=null;
        if ((onelist.get("photopath")==null)||onelist.get("photopath")==""){
            resultMap.put("path","201");
        }else {
            photopath = onelist.get("photopath").toString();
            resultMap.put("path",photopath);
        }
        resultMap.put("list",onelist);
        return resultMap;
    }

    @Override
    public Map getCourseName(Map map) {
        Map result = new HashMap();
        result.put("list",trainerDao.getCourseName(map));
        return result;
    }

    /**
     * 添加
     * @param map
     * @return
     */
    @Override
    public int add(Map map) {
        return trainerDao.add(map);
    }

    /**
     * 更新
     * @param map
     * @return
     */
    @Override
    public int update(Map map) {
        return trainerDao.update(map);
    }

    /**
     * 删除
     * @param trainerId
     * @return
     */
    @Override
    public int delete(int trainerId) {
        return trainerDao.delete(trainerId);
    }
}
